package cn.sxt.seata.controller;

import cn.sxt.seata.entity.Account;
import cn.sxt.seata.entity.CommonResult;
import cn.sxt.seata.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: --
 * @author：Bing
 * @date：2021/4/19 15:46
 * @version：1.0
 */
@RestController
public class AccountController {
    @Autowired
    private AccountService accountService;

    @RequestMapping("account/decrease")
    public CommonResult decrease(Long userId, Long money) {
        Account account1 = accountService.selectByPrimaryKey(1l);
        Account account = Account.builder()
                .id(1l)
                .userId(userId)
                .total(1000l)
                .used(account1.getUsed()+money)
                .residue(account1.getResidue() - money).build();
        accountService.updateByPrimaryKey(account);
        return new CommonResult(200, "账户金额扣减成功------------------>");
    }
}
